<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="keywords" content="">
    <meta name="description" content="">
	<link rel="stylesheet" href="http://cmanage.shinechain.io/vendor/css/weuix.min.css" />
	<link rel="icon" type="image/png" href="http://cmanage.shinechain.io/imgs/favicon.ico" />
	<title>区块链推广管理中心</title>
</head>
<style>
body{
	background: #ffffff;
}
.main{
	width: 80%;
	margin: 0 auto;
}
.main>.title{
	text-align: center;
	margin-top: 5%;
}
#template{
	display: none;
}
.block{
	font-size: 25px;
    line-height: 60px;
    height: 60px;
}
.block:hover{
	background: #f5f5f5;
}
.block>.ctrl{
    text-align: right;
    display: inline-block;
    float: right;
    height: 100%;
}
.block .weui_switch{
	vertical-align: middle;
}
</style>
<body>
<div class='main' style="position: relative;">
		<a href="/telegram.html" style="position: absolute; top: -10px;"><img src="http://cmanage.shinechain.io/imgs/return.jpg" height="48" width="48" style="vertical-align:middle;" /></a>
	<h2 class='title'>自动踢人</h2>
	<div id='template' class='block'>
		{{index}}、{{name}}
		<div class='ctrl'>
			<input class="weui_switch" type="checkbox" {{checked}} data-slug='{{slug}}'>
		</div>
	</div>
</div>

<script src='http://cmanage.shinechain.io/vendor/js/zepto.min.js'></script>
<script>
$(function(){
	var options = [{
		'name':'累计被三次删除消息',
		'checked': '',
		'slug': 'kitManWhoDeleteThreeMsg'
		},{
		'name':'用户名字过长,带有微信、电报拉人等字眼(广告嫌疑)',
		'checked': '',
		'slug': 'deleteLongUsername'
	}];
	var setButton = function() {
					$('.block').each(function() {
						if(!$(this).find('.title input').is(":checked")) {
							$(this).find('.body a').hide();
							$(this).find('.body p').show();
						} else {
							$(this).find('.body a').show();
							$(this).find('.body p').hide();
						}
						if($(this).find('.body a').attr('href') == '') {
							$(this).find('.body a').hide();
							$(this).find('.body p').show();
						}
					})
				}
				var ip = 'http://bot.shinechain.io';
				var clickThing = function (){
					$('.weui_switch').click(function() {
							var slug = $(this).data('slug');
							var checked = $(this).is(":checked");
							var self = $(this);
							$.get(ip+'/botApi/botMethod?botMethod='+slug, function(result){
								if (result && result.status == 200){
									if(result.botMethod == true){
									self.prop("checked",true); 
									}else{
									self.prop("checked",false); 
									}	
									setButton();
								}else {
									window.alert(result.errorMsg);
								}
							});
						});
				}
				var getInfo = function () {

					$.get(ip + '/botApi/getAll', function(res) {
						options.map(function(value, index) {
							var slug = value.slug;
							if(res.botMethod[slug] == true) {
								options[index]['checked'] = 'checked';
							}
						});
						/*
							res.botMethod.map(function(value, index){
								options[index]['checked'] = (value == false ? '' : 'checked');
							});*/

						options.map(function(value, index){
							var html = $('#template').clone().attr('id', '').prop("outerHTML");
							html = html.replace("{{index}}", index + 1);
							for(var index in value){
								html = html.replace("{{"+index+"}}", value[index]);
							}
							$('.main').append(html)
						});
						setButton();
						clickThing();
					})
				}
				getInfo();
})
</script>
</body>
</html>